import { Component, Vue } from 'vue-property-decorator'
import InfoBlock from '@profile/util/info_block/Index.vue';
import axios from '@axios/user';
import { User } from '@entity/user';

@Component({
    components: {
        InfoBlock
    }
})
export class MessageNotify extends Vue {

    /** 我自己(深拷贝) */
    private me: User = this.$store.getters.me(true);

    /** 源数据 */
    private source: String = '';

    created() {
        this.source = JSON.stringify(this.me);
    }

    /**
     * 更新信息, 服务端更新成功后才更新本地
     */
    private save(): void {
        axios.update.notify(this.me).then(res => {
            if (res) {
                this.me = this.$store.getters.updateMe(this.me);
            }
        });
    }

    
    /**
     * 判断是否进行了修改
     * 只需要将当前数据与源数据进行比较即可
     */
    private get changed(): Boolean {
        return this.source.isEmpty() || JSON.stringify(this.me) === this.source;
    }

}